package com.jcfk.eam.controller.mould;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.eam.domain.dto.mould.EamMouldEmailConfigDTO;
import com.jcfk.eam.domain.query.mould.EamMouldEmailConfigQuery;
import com.jcfk.eam.service.mould.EamMouldEmailConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.common.core.utils.ExcelUtils;
/**
 * 模具邮件发送配置表
 *
 * @author yrl
 * @email 
 * @date 2025-07-25
 */
@Api(tags = {"模具邮件发送配置表管理"})
@RestController
@RequestMapping("eammouldemailconfig")
public class EamMouldEmailConfigController {
    @Autowired
    private EamMouldEmailConfigService eamMouldEmailConfigService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamMouldEmailConfigQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询模具邮件发送配置表")
    @PostMapping("/queryByPage")
    public RetPage<EamMouldEmailConfigDTO> queryByPage(@RequestBody ReqPageParam<EamMouldEmailConfigQuery> requestParam) {
        DataPage<EamMouldEmailConfigDTO> page = new DataPage<EamMouldEmailConfigDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamMouldEmailConfigDTO.class);
        page = eamMouldEmailConfigService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  模具邮件发送配置表
     * 根据id 查询详情
     */
    @ApiOperation("查询模具邮件发送配置表")
    @GetMapping("/get/{id}")
    public RetResult<EamMouldEmailConfigDTO> get(@PathVariable("id") String id) {
            EamMouldEmailConfigDTO item = eamMouldEmailConfigService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理模具邮件发送配置表
     */
    @ApiOperation("保存模具邮件发送配置表")
    @PostMapping("/save")
    @RequestLogHeader(modular = "模具邮件发送配置表管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamMouldEmailConfigDTO eamMouldEmailConfig) {
        // 数据校验
        RetResult ret = eamMouldEmailConfigService.isValid(eamMouldEmailConfig);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamMouldEmailConfig.getId())){
            // 新增
            eamMouldEmailConfigService.insert(eamMouldEmailConfig);
        } else{
            // 更新
            eamMouldEmailConfigService.update(eamMouldEmailConfig);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除模具邮件发送配置表
     */
    @ApiOperation("批量删除模具邮件发送配置表")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "模具邮件发送配置表管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamMouldEmailConfigDTO eamMouldEmailConfig) {
        return RetResult.ok(eamMouldEmailConfigService.logicDeleteList(eamMouldEmailConfig));
    }





    /**
     *  删除模具邮件发送配置表
     */
    @ApiOperation("删除模具邮件发送配置表")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "模具邮件发送配置表管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamMouldEmailConfigService.deleteItem(id);
        return RetResult.ok();
    }
}
